import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";


//全局注册
import request from "./network/request";
Vue.prototype.request = request;

//引入vant组件
import Vant from 'vant';
import { Lazyload } from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);
Vue.use(Lazyload);
// 注册时设置`lazyComponent`选项
Vue.use(Lazyload, {
    lazyComponent: true,
});


Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.auth)) {
        //判断是否登录
        if (to.name == 'Login') {
            next()
        } else {
            //登录bug 需要先进行token认证 才能登录
            if (localStorage.getItem('Authorization')) {
                next();
            } else {
                next({
                    path: '/login',
                    query: { redirect: to.fullPath }
                })
            }
        }
    } else {
        next()
    }
})

// 引入三方插件dayjs
import dayjs from "dayjs";

Vue.filter('newDate', (val, format) => {
    return dayjs(val).format(format);
})


new Vue({
    router,
    store,
    render: (h) => h(App),
}).$mount("#app");